from langchain_deepseek import ChatDeepSeek
from typing import Optional
from typing_extensions import Annotated, TypedDict
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

llm = ChatDeepSeek(
    model="deepseek-chat",  # 模型名称
    temperature=0,         # 控制生成随机性(0-1)
    max_tokens=None,       # 最大输出token数
    timeout=None,          # 超时设置
    max_retries=2,         # 失败重试次数
    api_key="sk-XXXXXXXX"
)

class Joke(TypedDict):
    """Joke to tell user."""

    setup: Annotated[str, ..., "The setup of the joke"]

    # Alternatively, we could have specified setup as:

    # setup: str                    # no default, no description
    # setup: Annotated[str, ...]    # no default, no description
    # setup: Annotated[str, "foo"]  # default, no description

    punchline: Annotated[str, ..., "The punchline of the joke"]
    rating: Annotated[Optional[int], None, "How funny the joke is, from 1 to 10"]
structured_llm = llm.with_structured_output(Joke,include_raw=True)
print(structured_llm.invoke("Tell me a joke about cats"))
